package com.jewelry.web.action;

import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jewelry.service.IUserService;
import com.jewelry.vo.UserVO;

/**
 * 系统登录登出
 * 
 * @author yangfeng
 * 
 */
public class LoginAction extends HttpAction {
	
	private static Logger logger = LoggerFactory.getLogger(LoginAction.class);

	private static final long serialVersionUID = -1167398688514342887L;
	
	//=================================
	private IUserService userService;

	public IUserService getUserService() {
		return userService;
	}

	public void setUserService(IUserService userService) {
		this.userService = userService;
	}
	
	private UserVO userVO; 
	
	public UserVO getUserVO() {
		return userVO;
	}

	public void setUserVO(UserVO userVO) {
		this.userVO = userVO;
	}
	//=====================================

	public String login() {
		return SUCCESS;
	}

	public String doLogin() {
		if(logger.isDebugEnabled()){
			logger.debug("doLoginin be invoked ... ");
		}
		boolean result = userService.doLogin(userVO, session);
		
		if(logger.isDebugEnabled()){
			logger.debug("doLoginin invoked end loginResult={}",result);
		}
		
		if(result){
			setMessage("");
			return userService.getLoginResult(session);
		}else{
			setMessage("登录名或登录密码错误");
			return LOGIN;
		}
	}

	public String doLogout() {
		HttpSession httpSession = httpRequest.getSession();
		httpSession.invalidate();
		return SUCCESS;
	}

}
